package com.example.yian.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.example.yian.entity.CaptchaEntity;
import com.example.yian.entity.ProjectInfo;
import com.example.yian.mapper.CaptchaEntityMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Optional;

@Service
public class CaptchaService {

    @Autowired
    private CaptchaEntityMapper captchaEntityMapper;
    public CaptchaEntity updateCaptchaEntity(Long userId, String code) {
        // 使用自定义的 selectByCode 方法查询
        CaptchaEntity captchaEntity = captchaEntityMapper.selectByCode(code);

        if (captchaEntity == null) {
            throw new IllegalArgumentException("CaptchaEntity 不存在");
        }

        // 使用自定义的 updateBindUserId 方法更新 bindUserId
        captchaEntityMapper.updateBindUserId(userId, code);

        return captchaEntity;
    }

    public Optional<CaptchaEntity> getCaptchaEntityByUserId(Long userId) {
        CaptchaEntity captchaEntity = captchaEntityMapper.selectByUserId(userId);
        return Optional.ofNullable(captchaEntity);
    }
}
